package com.sjg.sys.service;

import com.sjg.sys.entity.SysPage;
import com.sjg.sys.entity.SysUser;
import com.sjg.sys.utils.CommUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

import com.sjg.sys.dao.SysUserDao;

@Service
public class SysUserService{

    @Resource
    private SysUserDao sysUserDao;

    public int insert(SysUser pojo){
        pojo.setId(CommUtil.getPrimaryKey());
        return sysUserDao.insert(pojo);
    }

    public int insertSelective(SysUser pojo){
        pojo.setId(CommUtil.getPrimaryKey());
        return sysUserDao.insertSelective(pojo);
    }

    public int insertList(List<SysUser> pojos){
        for(SysUser user:pojos){
            user.setId(CommUtil.getPrimaryKey());
        }
        return sysUserDao.insertList(pojos);
    }

    public int update(SysUser pojo){
        return sysUserDao.update(pojo);
    }

    public SysUser selectUnlockedUser(String loginName){
        /*锁定 1：启用、2：禁用*/
        return sysUserDao.findbyLoginNameAndLocked(loginName,1);
    }

    public SysPage<SysUser> selectByUserPage(SysPage<SysUser> page){
        if(page.getPojo()==null){
            page.setPojo(new SysUser());
        }
        page.setRows(sysUserDao.findbyUserPage(page));
        page.setRowsCount(sysUserDao.findRowCountById());
        page.getPageCount();
        return page;
    }
}
